using System;
using Oracle.ManagedDataAccess.Client;
using OracleInternal.Common;

namespace OracleInternal.TTC
{
	internal class TTCColumnInfo
	{
		internal static int UDSFCOL_IS_IDENTITY = 16;

		internal static int UDSFCOL_IS_GEN_ALWAYS = 32;

		internal static int UDSFCOL_IS_GEN_BY_DEFAULT_ON_NULL = 64;

		internal static int UDSFCOL_IS_JSON = 256;

		internal static int UDSFCOL_IS_VALUELOB = 1024;

		internal static int UDSFCOL_IS_OSON = 2048;

		internal static void ReadMessage(MarshallingEngine mEngine, ColumnDescribeInfo colMetaData, bool bIgnoreMetadata)
		{
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)131328, OracleTraceClassName.TTCColumnInfo, OracleTraceFuncName.ReadMessage);
			}
			try
			{
				TTCColumnMetaData.ReadMessage(mEngine, colMetaData, bIgnoreMetadata);
				char[] t = null;
				if (!bIgnoreMetadata)
				{
					int[] array = new int[1];
					short num = mEngine.UnmarshalUB1();
					colMetaData.m_isNullAllowed = ((num > 0) ? true : false);
					mEngine.UnmarshalUB1();
					byte[] array2 = mEngine.UnmarshalDALC(bIgnoreData: false, array);
					if (array2 != null)
					{
						if (t == null)
						{
							t = mEngine.m_charArrayPooler.Dequeue();
						}
						colMetaData.pColAlias = mEngine.m_dbCharSetConv.ConvertBytesToString(array2, 0, array[0], t);
					}
					array2 = mEngine.UnmarshalDALC(bIgnoreData: true);
					if ((array2 = mEngine.UnmarshalDALC(bIgnoreData: false, array)) != null)
					{
						if (t == null)
						{
							t = mEngine.m_charArrayPooler.Dequeue();
						}
						if (mEngine.m_dbCharSetConv.ConvertBytesToString(array2, 0, array[0], t).Equals("XMLTYPE", StringComparison.InvariantCultureIgnoreCase))
						{
							colMetaData.m_dataType = 109;
							colMetaData.bIsXmlType = true;
						}
					}
					if (t != null)
					{
						mEngine.m_charArrayPooler.Enqueue(ref t);
					}
				}
				else
				{
					mEngine.UnmarshalUB1(bIgnoreData: true);
					mEngine.UnmarshalUB1(bIgnoreData: true);
					mEngine.UnmarshalDALC(bIgnoreData: true);
					mEngine.UnmarshalDALC(bIgnoreData: true);
					mEngine.UnmarshalDALC(bIgnoreData: true);
				}
				if (mEngine.NegotiatedTTCVersion < 3)
				{
					return;
				}
				mEngine.UnmarshalUB2(bIgnoreData: true);
				if (mEngine.NegotiatedTTCVersion >= 6)
				{
					if (!bIgnoreMetadata)
					{
						int num2 = (int)mEngine.UnmarshalUB4();
						colMetaData.m_bIsIdentityCol = (num2 & UDSFCOL_IS_IDENTITY) != 0;
						colMetaData.m_bIsGenAlways = (num2 & UDSFCOL_IS_GEN_ALWAYS) != 0;
						colMetaData.m_bIsGenByDefaultOnNull = (num2 & UDSFCOL_IS_GEN_BY_DEFAULT_ON_NULL) != 0;
						colMetaData.m_bIsValueLob = (num2 & UDSFCOL_IS_VALUELOB) != 0;
					}
					else
					{
						mEngine.UnmarshalUB4(bIgnoreData: true);
					}
				}
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Private, (OracleTraceTag)268566528, OracleTraceClassName.TTCColumnInfo, OracleTraceFuncName.ReadMessage, ex);
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPrivate)
				{
					Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)131584, OracleTraceClassName.TTCColumnInfo, OracleTraceFuncName.ReadMessage);
				}
			}
		}
	}
}
